Skip to content

test: zk dispute game factory and registry#19872

Open
0xChin wants to merge 25 commits intoethereum-optimism:developfrom
defi-wonderland:test/zk-dispute-game-factory-and-registry
Open

test: zk dispute game factory and registry#19872
0xChin wants to merge 25 commits intoethereum-optimism:developfrom
defi-wonderland:test/zk-dispute-game-factory-and-registry

Conversation

@0xChin
Copy link
Copy Markdown
Contributor

@0xChin 0xChin commented Apr 1, 2026

Summary

Adds ZK dispute game test coverage for DisputeGameFactory and AnchorStateRegistry, proving both contracts work correctly with the new ZK_DISPUTE_GAME type (game type 10).

Changes

DisputeGameFactory.t.sol

Restructuring:

  • Extracted ZK tests from generic factory test contracts into dedicated _ZkDisputeGame_ contracts
  • Moved test_create_implArgs_succeeds into DisputeGameFactory_Create_FaultDisputeGame_Test for explicit game-type separation
  • Created DisputeGameFactory_ZkDisputeGame_TestInit abstract base with shared helpers (_createZKGame, _assertZKGameFactoryStorage, _assertZKGameCWIA)

New test contracts:

  • DisputeGameFactory_Create_ZkDisputeGame_Test — create happy path, zero bond, wrong bond, no impl, duplicate UUID
  • DisputeGameFactory_SetImplementation_ZkDisputeGame_Test — impl+args storage, non-owner revert
  • DisputeGameFactory_SetInitBond_ZkDisputeGame_Test — bond set/update, non-owner revert
  • DisputeGameFactory_FindLatestGames_ZkDisputeGame_Test — multi-game ordering

New generic test:

  • testFuzz_create_overpayment_reverts — verifies factory rejects overpayment (sends more ETH than required bond)

AnchorStateRegistry.t.sol

New abstract base:

  • AnchorStateRegistry_ZkDisputeGame_TestInit — creates a real ZK game via factory, provides _mockZkGameAsValid() helper

New test contracts:

  • AnchorStateRegistry_SetAnchorState_ZkDisputeGame_Test — valid newer state, older game claim rejected, blacklisted, retired, challenger wins, not finalized (6 tests)
  • AnchorStateRegistry_IsGameClaimValid_ZkDisputeGame_Test — valid claim, blacklisted, retired, not respected (4 tests)
  • AnchorStateRegistry_IsGameProper_ZkDisputeGame_Test — all conditions met, blacklisted (2 tests)
  • AnchorStateRegistry_BlacklistDisputeGame_ZkDisputeGame_Test — blacklist succeeds (1 test)

Test plan

  • DEV_FEATURE__ZK_DISPUTE_GAME=true forge test --match-path test/dispute/DisputeGameFactory.t.sol
  • DEV_FEATURE__ZK_DISPUTE_GAME=true forge test --match-path test/dispute/AnchorStateRegistry.t.sol
  • just pre-pr passes

@0xChin 0xChin self-assigned this Apr 1, 2026
function setUp() public virtual override {
super.setUp();

skipIfDevFeatureDisabled(DevFeatures.ZK_DISPUTE_GAME);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every this is testes when zk dispute game is enabled. Maybe create one to check that reverts if the flag is disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the flag disabled, the ZK game implementation wouldn't be deployed or registered in the factory so there's no zkGameProxy to test against. The ASR and factory are game-type agnostic; they don't check the feature flag themselves. The flag only gates deployment at the OPCM level, which is already covered by test_upgrade_enableZKGameWithoutDevFeature_reverts in the OPCM tests. At the ASR/factory level, "flag disabled" just means "no ZK game exists," which isn't a ZK-specific scenario worth testing here.

/// @title DisputeGameFactory_ZkDisputeGame_TestInit
/// @notice Reusable test initialization for ZKDisputeGame factory tests.
abstract contract DisputeGameFactory_ZkDisputeGame_TestInit is DisputeGameFactory_TestInit {
IZKVerifier zkVerifier;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's declared as a state var in TestInit because both _createZKGameWithParams (which sets it) and _assertZKGameCWIA (which reads it) live there. The alternative would be returning it from _createZKGameWithParams and passing it as an extra param to _assertZKGameCWIA, but I'd rather keep it this way

Copy link
Copy Markdown
Contributor

@0xOneTony 0xOneTony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requesting changes above^

@0xOneTony
Copy link
Copy Markdown
Contributor

/ci authorize a651fe6

@0xChin
Copy link
Copy Markdown
Contributor Author

0xChin commented Apr 2, 2026

/ci authorize c41aa6f

@ethereum-optimism ethereum-optimism deleted a comment from 0xChin Apr 3, 2026
@ashitakah
Copy link
Copy Markdown
Contributor

ashitakah commented Apr 3, 2026

/ci authorize f64a2c6

@0xChin
Copy link
Copy Markdown
Contributor Author

0xChin commented Apr 3, 2026

/ci authorize 92e894d

@0xChin
Copy link
Copy Markdown
Contributor Author

0xChin commented Apr 3, 2026

/ci authorize 1a786ef

@0xChin 0xChin marked this pull request as ready for review April 3, 2026 16:11
@0xChin 0xChin requested review from a team and smartcontracts April 3, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants